﻿Imports System.Collections.Generic
Imports System.Data.SqlClient
Namespace QuanLyKhachHang
    Public Class DonHangDAL
        Public Function DonHangBan_GetItems(ByVal TrangThai As String, ByVal TuNgay As Integer, ByVal DenNgay As Integer) As List(Of DonHang)
            Try
                Dim SQLHelper As New SQLDataHelper
                Dim Reader As SqlDataReader
                SQLHelper.AddParameter("@TrangThai", TrangThai)
                SQLHelper.AddParameter("@TuNgay", TuNgay)
                SQLHelper.AddParameter("@DenNgay", DenNgay)
                Reader = SQLHelper.ExecuteReader("sp_DonHangBan", CommandType.StoredProcedure)
                Dim item As DonHang
                Dim list As New List(Of DonHang)
                While (Reader.Read())
                    item = New DonHang
                    item.STT = Reader("STT").ToString()
                    item.IDDonHangBan = Integer.Parse(Reader("IDDonHangBan").ToString())
                    item.So = Reader("So").ToString()
                    item.TenKhachHang = Reader("TenKhachHang").ToString()
                    item.MaSoThue = Reader("MaSoThue").ToString()
                    item.DiaChi = Reader("DiaChi").ToString()
                    item.NgayBan = Reader("NgayBan").ToString()
                    item.TongTien = Single.Parse(Reader("TongTien").ToString())
                    item.TrangThai = Reader("TrangThai").ToString()
                    list.Add(item)
                End While
                Return list
            Catch ex As Exception
                Throw ex
            End Try
        End Function
        Public Function DonHangBan_GetItems_TenKhachHang(ByVal TrangThai As String, ByVal TenKhachHang As String) As List(Of DonHang)
            Try
                Dim SQLHelper As New SQLDataHelper
                Dim Reader As SqlDataReader
                SQLHelper.AddParameter("@TrangThai", TrangThai)
                SQLHelper.AddParameter("@TenKhachHang", TenKhachHang)
                Reader = SQLHelper.ExecuteReader("sp_DonHangBan_TenKhachHang", CommandType.StoredProcedure)
                Dim item As DonHang
                Dim list As New List(Of DonHang)
                While (Reader.Read())
                    item = New DonHang
                    item.STT = Reader("STT").ToString()
                    item.IDDonHangBan = Integer.Parse(Reader("IDDonHangBan").ToString())
                    item.So = Reader("So").ToString()
                    item.TenKhachHang = Reader("TenKhachHang").ToString()
                    item.MaSoThue = Reader("MaSoThue").ToString()
                    item.DiaChi = Reader("DiaChi").ToString()
                    item.NgayBan = Reader("NgayBan").ToString()
                    item.TongTien = Single.Parse(Reader("TongTien").ToString())
                    item.TrangThai = Reader("TrangThai").ToString()
                    list.Add(item)
                End While
                Return list
            Catch ex As Exception
                Throw ex
            End Try
        End Function
        Public Function DonHangBan_GetItems_SoHoaDon(ByVal TrangThai As String, ByVal SoHoaDon As String) As List(Of DonHang)
            Try
                Dim SQLHelper As New SQLDataHelper
                Dim Reader As SqlDataReader
                SQLHelper.AddParameter("@TrangThai", TrangThai)
                SQLHelper.AddParameter("@SoHoaDon", SoHoaDon)
                Reader = SQLHelper.ExecuteReader("sp_DonHangBan_SoHoaDon", CommandType.StoredProcedure)
                Dim item As DonHang
                Dim list As New List(Of DonHang)
                While (Reader.Read())
                    item = New DonHang
                    item.STT = Reader("STT").ToString()
                    item.IDDonHangBan = Integer.Parse(Reader("IDDonHangBan").ToString())
                    item.So = Reader("So").ToString()
                    item.TenKhachHang = Reader("TenKhachHang").ToString()
                    item.MaSoThue = Reader("MaSoThue").ToString()
                    item.DiaChi = Reader("DiaChi").ToString()
                    item.NgayBan = Reader("NgayBan").ToString()
                    item.TongTien = Single.Parse(Reader("TongTien").ToString())
                    item.TrangThai = Reader("TrangThai").ToString()
                    list.Add(item)
                End While
                Return list
            Catch ex As Exception
                Throw ex
            End Try
        End Function
    End Class
End Namespace
